package com.vvvtimes.demo.controller;

import com.vvvtimes.demo.common.dto.RestResponse;
import com.vvvtimes.demo.domain.dto.WeatherCityDTO;
import com.vvvtimes.demo.domain.mybatis.City;
import com.vvvtimes.demo.domain.vo.WeatherVo;
import com.vvvtimes.demo.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/weather")
public class WeatherController {

    @Autowired
    private WeatherService weatherService;

    @RequestMapping(value = "city/{id:1[0-9]{8}}", method = {RequestMethod.POST, RequestMethod.GET})
    public RestResponse<WeatherVo> loadApi(@PathVariable("id") String id) {
        return weatherService.loadApi(id);
    }

    @RequestMapping(value = "queryWeatherCity", method = {RequestMethod.POST, RequestMethod.GET})
    public RestResponse<List<City>> queryWeatherCity(@RequestBody WeatherCityDTO weatherCityDTO) {
        return weatherService.queryWeatherCity(weatherCityDTO);
    }

    @RequestMapping(value = "initJsonToDb", method = {RequestMethod.POST, RequestMethod.GET})
    public RestResponse<Integer> initJsonToDb() {
        return weatherService.initJsonToDb();
    }


}

